<template>
  <h1>循环指令</h1>
  <ul>
    <li v-for="item in 5">{{ item }}</li>
  </ul>
  <ul>
    <li v-for="item in arr">{{ item }}</li>
  </ul>
  <table border="1">
    <caption>商品列表</caption>
    <tr>
      <th>编号</th>
      <th>名称</th>
      <th>价格</th>
      <th>库存</th>
      <th>操作</th>
    </tr>
    <!--    index只能在item后面,不然显示不出来-->
    <tr v-for="(item,index) in productArr">
      <td>{{ index + 1 }}</td>
      <td>{{ item.name }}</td>
      <td>{{ item.price }}</td>
      <td>{{ item.num }}</td>
      <td>
        <button @click="del(index)">删除</button>
      </td>
    </tr>
  </table>
</template>

<script setup>
import {ref} from "vue";

const arr = ref(['张三', '李四', '王五']);
const productArr = ref([
  {name: 'iphone', price: 8000, num: 10000},
  {name: 'vivo', price: 5000, num: 2000},
  {name: '华为', price: 6000, num: 500},
  {name: '小米', price: 5000, num: 100}
]);
const del = (i) => {
  // 表示从第i个开始删除1个
  productArr.value.splice(i, 1);
}
</script>

<style scoped>

</style>